var app = getApp();
var host = app.data.host;
var httpUtil = require("../utils/httpUtil.js")
var getClerkUrl = host +"getClerks"//美容师列表
var getAppointmentTimeUrl = host + "getAppointmentTime"; //获取美容师预约档期
var addAppointmentUrl=host+"addAppointment";//添加预约
var getTodayAppointmentUrl = host +"getTodayAppointmentRecord"//今天预约记录

//美容师类表
function getClerks(cb){
  httpUtil.get(getClerkUrl,null,cb)
}
//获取预约档期
function getAppointmentTime(id, cb) {
  var data = {
    id: id,
  }
  httpUtil.get(getAppointmentTimeUrl, data, cb)
}
//美容师今天预约记录
function getTodayAppointment(id,cb){
  var data={
    id:id
  }
  httpUtil.get(getTodayAppointmentUrl,data,cb)
}
//添加预约
function addAppointment(data, cb) {
  var user = app.data.user
  data.customerId=user.id
  data.customerName=user.name
  data.cellphone=user.cellphone
  var list=data.projects
  //todo
  var projects=[]
  for(var i=0;i<list.length;i++){
    var node=list[i]
    var temp={
      goodsId:node.id,
      goodsName:node.name,
      goodsPrice:node.price,
      goodsImgUrl:node.imgUrl,
      goodsType:node.type
    }
    projects.push(temp)
  }
  data.projects=JSON.stringify(projects)
  httpUtil.post(addAppointmentUrl,data,cb)
}
module.exports = {
  getClerks: getClerks,
  getTodayAppointment: getTodayAppointment,
  getAppointmentTime: getAppointmentTime,
  addAppointment: addAppointment,
}